# MGPI makefile, by cmaster.matso
VERSION = 0.6.9
NAME = mgpi_

CC = gcc
LFLAGS = -shared
CFLAGS = -pedantic -fpic -O3 -Wall
CLEAN = compmdl/bin/compmdl.o \
	ehimdl/bin/ehimdl.o \
	g2dmdl/bin/g2dmdl.o \
	g3dmdl/bin/g3dmdl.o \
	g3dmdl/bin/mdl.o \
	g3dmdl/bin/md2.o \
	g3dmdl/bin/md5mesh.o \
	g3dmdl/bin/md5anim.o \
	g3dmdl/bin/smd.o \
	g3dmdl/bin/hmp.o \
	g3dmdl/bin/sbx.o \
	g3dmdl/bin/obj.o \
	g3dmdl/bin/roeskva.o \
	grbcrl/bin/grbclr.o \
	ievtmdl/bin/ievtmdl.o \
	thrlib/bin/thrlib.o \
	main/bin/mgpi.o \
	math/bin/calculus.o \
	math/bin/gpuc.o \
    errors/bin/errors.o \
	main/bin/stddefs.o \
	main/bin/libmgpi*

TEMP = compmdl/src/*~ \
       ehimdl/src/*~ \
       g2dmdl/src/*~ \
       g3dmdl/src/*~ \
       grbcrl/src/*~ \
       ievtmdl/src/*~ \
       thrlib/src/*~ \
       main/src/*~ \
       math/src/*~ \
       errors/src/*~ \
       *~ \
       .*~
SRCARCH = compmdl/src/$(NAME)compmdl.c compmdl/src/$(NAME)compmdl.h \
	  ehimdl/src/$(NAME)ehimdl.c ehimdl/src/$(NAME)ehimdl.h \
	  g2dmdl/src/$(NAME)g2dmdl.c g2dmdl/src/$(NAME)g2dmdl.h \
	  g3dmdl/src/$(NAME)g3dmdl.c g3dmdl/src/$(NAME)g3dmdl.h \
	  g3dmdl/src/$(NAME)roeskva.c g3dmdl/src/$(NAME)roeskva.h \
	  g3dmdl/src/mdl.c g3dmdl/src/mdl.h \
	  g3dmdl/src/md2.c g3dmdl/src/md2.h \
	  g3dmdl/src/md5mesh.c g3dmdl/src/md5anim.c g3dmdl/src/md5model.h \
	  g3dmdl/src/smd.c g3dmdl/src/smd.h \
	  g3dmdl/src/hmp.c g3dmdl/src/hmp.h \
	  g3dmdl/src/sbx.c g3dmdl/src/sbx.h \
	  g3dmdl/src/obj.c g3dmdl/src/obj.h \
	  grbclr/src/$(NAME)grbclr.c grbclr/src/$(NAME)grbclr.h \
	  ievtmdl/src/$(NAME)ievtmdl.c ievtmdl/src/$(NAME)ievtmdl.h \
	  thrlib/src/$(NAME)thrlib.c thrlib/src/$(NAME)thrlib.h \
	  errors/src/$(NAME)errors.c errors/src/$(NAME)errors.h \
	  main/src/$(NAME)stddefs.c main/src/$(NAME)stddefs.h \
	  math/src/$(NAME)calculus.c math/src/$(NAME)calculus.h \
	  math/src/$(NAME)gpuc.c math/src/$(NAME)gpuc.h \
	  main/src/mgpi.c main/src/mgpi.h \
	  gmgpi.h mgpi.h mgpi_game.h \
	  COPYING \
	  makefile \
	  makefile_win32 \
	  install.bat \
	  install \
	  inst \
	  mkbindirs \
	  mgpiinstall

COMP = compmdl/bin/compmdl.o
EHI = ehimdl/bin/ehimdl.o
G2D = g2dmdl/bin/g2dmdl.o
G3D = g3dmdl/bin/g3dmdl.o
RVK = g3dmdl/bin/roeskva.o
MDL = g3dmdl/bin/mdl.o
MD2 = g3dmdl/bin/md2.o
MD5M = g3dmdl/bin/md5mesh.o
MD5A = g3dmdl/bin/md5anim.o
SMD = g3dmdl/bin/smd.o
SBX = g3dmdl/bin/sbx.o
HMP = g3dmdl/bin/hmp.o
OBJ = g3dmdl/bin/obj.o
GRBCLR = grbclr/bin/grbclr.o
IEVT = ievtmdl/bin/ievtmdl.o
THRLIB = thrlib/bin/thrlib.o
MAIN = main/bin/mgpi.o
STDF = main/bin/stddefs.o
CALC = math/bin/calculus.o
GPUC = math/bin/gpuc.o
ERR = errors/bin/errors.o
MBIN = main/bin/
LIB = libmgpi.so.$(VERSION)
OLIB = $(MBIN)$(LIB)

DATE = `date +%Y%m%d%H%M`
SDATE = `date +%Y%m%d`

all: $(OLIB)

$(COMP): compmdl/src/$(NAME)compmdl.c compmdl/src/$(NAME)compmdl.h
	$(CC) -c $(CFLAGS) compmdl/src/$(NAME)compmdl.c -o $(COMP)

$(EHI): ehimdl/src/$(NAME)ehimdl.c ehimdl/src/$(NAME)ehimdl.h
	$(CC) -c $(CFLAGS) ehimdl/src/$(NAME)ehimdl.c -o $(EHI)

$(G2D): g2dmdl/src/$(NAME)g2dmdl.c g2dmdl/src/$(NAME)g2dmdl.h
	$(CC) -c $(CFLAGS) g2dmdl/src/$(NAME)g2dmdl.c -o $(G2D)

$(G3D): g3dmdl/src/$(NAME)g3dmdl.c g3dmdl/src/$(NAME)g3dmdl.h g3dmdl/src/mdl.h
	$(CC) -c $(CFLAGS) g3dmdl/src/$(NAME)g3dmdl.c -o $(G3D)

$(RVK): g3dmdl/src/$(NAME)roeskva.c g3dmdl/src/$(NAME)roeskva.h g3dmdl/src/$(NAME)g3dmdl.h
	$(CC) -c $(CFLAGS) g3dmdl/src/$(NAME)roeskva.c -o $(RVK)

$(MDL): g3dmdl/src/mdl.c g3dmdl/src/mdl.h
	$(CC) -c $(CFLAGS) g3dmdl/src/mdl.c -o $(MDL)

$(MD2): g3dmdl/src/md2.c g3dmdl/src/md2.h
	$(CC) -c $(CFLAGS) g3dmdl/src/md2.c -o $(MD2)

$(MD5M): g3dmdl/src/md5mesh.c g3dmdl/src/md5model.h
	$(CC) -c $(CFLAGS) g3dmdl/src/md5mesh.c -o $(MD5M)

$(MD5A): g3dmdl/src/md5anim.c g3dmdl/src/md5model.h
	$(CC) -c $(CFLAGS) g3dmdl/src/md5anim.c -o $(MD5A)

$(SMD): g3dmdl/src/smd.c g3dmdl/src/smd.h
	$(CC) -c $(CFLAGS) g3dmdl/src/smd.c -o $(SMD)

$(SBX): g3dmdl/src/sbx.c g3dmdl/src/sbx.h
	$(CC) -c $(CFLAGS) g3dmdl/src/sbx.c -o $(SBX)

$(HMP): g3dmdl/src/hmp.c g3dmdl/src/hmp.h
	$(CC) -c $(CFLAGS) g3dmdl/src/hmp.c -o $(HMP)

$(OBJ): g3dmdl/src/obj.c g3dmdl/src/obj.h
	$(CC) -c $(CFLAGS) g3dmdl/src/obj.c -o $(OBJ)

$(GRBCLR): grbclr/src/$(NAME)grbclr.c grbclr/src/$(NAME)grbclr.h
	$(CC) -c $(CFLAGS) grbclr/src/$(NAME)grbclr.c -o $(GRBCLR)

$(IEVT): ievtmdl/src/$(NAME)ievtmdl.c ievtmdl/src/$(NAME)ievtmdl.h
	$(CC) -c $(CFLAGS) ievtmdl/src/$(NAME)ievtmdl.c -o $(IEVT)

$(THRLIB): thrlib/src/$(NAME)thrlib.c thrlib/src/$(NAME)thrlib.h
	$(CC) -c $(CFLAGS) thrlib/src/$(NAME)thrlib.c -o $(THRLIB)

$(ERR): errors/src/$(NAME)errors.c errors/src/$(NAME)errors.h
	$(CC) -c $(CFLAGS) errors/src/$(NAME)errors.c -o $(ERR)

$(STDF): main/src/$(NAME)stddefs.c main/src/$(NAME)stddefs.h
	$(CC) -c $(CFLAGS) main/src/$(NAME)stddefs.c -o $(STDF)

$(CALC): math/src/$(NAME)calculus.c math/src/$(NAME)calculus.h
	$(CC) -c $(CFLAGS) math/src/$(NAME)calculus.c -o $(CALC)

$(GPUC): math/src/$(NAME)gpuc.c math/src/$(NAME)gpuc.h
	$(CC) -c $(CFLAGS) math/src/$(NAME)gpuc.c -o $(GPUC)

$(MAIN): main/src/mgpi.c main/src/mgpi.h
	$(CC) -c $(CFLAGS) main/src/mgpi.c -o $(MAIN)

MDLS = $(COMP) $(EHI) $(CALC) $(GPUC) $(ERR) $(STDF) $(G2D) $(G3D) $(RVK) $(MDL) $(MD2) $(MD5M) $(MD5A) $(SMD) $(SBX) $(HMP) $(OBJ) $(GRBCLR) $(IEVT) $(THRLIB) $(MAIN)

$(OLIB): $(MDLS)
	rm -f $(TEMP)
	$(CC) $(LFLAGS) $(MDLS) -o $(OLIB)
	cp $(OLIB) main/arch/$(LIB)_v"$(DATE)"

#Developer stuff
clean:
	rm -f $(TEMP)
	rm -f $(CLEAN)

source-arch-package:
	tar -cf arch/SOURCE-MGPI-$(VERSION)-$(SDATE).tar $(SRCARCH)

release-package:

#User stuff
install: all
	sh ./install $(LIB) $(OLIB) --install

uninstall:
	sh ./uinst $(LIB)
